package com.example.shopp_2301.createorder

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CreateOrderEntity
import com.example.base.entity.GetPreOderEntity
import com.example.base.entity.ParamCreateOrder
import com.example.base.mvvm.BaseModel
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CreateOrderViewModel:BaseViewModel() {
    //返回值--获取预下单
    val getSuccess = MutableLiveData<BaseModel<GetPreOderEntity>>()
    val getFail = MutableLiveData<String>()
    fun getPreOrder(preOrderNo:String){
        viewModelScope.launch {
            try {
                getSuccess.value = apiServer.getPreOrder(preOrderNo)
            }catch (e:Exception){
                getFail.value = e.message
            }
        }
    }
    //返回值  --创建订单
    val createSuccess = MutableLiveData<BaseModel<CreateOrderEntity>>()
    val createFail = MutableLiveData<String>()
    fun createOrder(body:ParamCreateOrder){
        viewModelScope.launch {
            try {
                createSuccess.value = apiServer.createOrder(body)
            }catch (e:Exception){
                createFail.value = e.message
            }
        }
    }
}